package com.formiaomiao.demain.controller;

import com.formiaomiao.demain.model.FriendBean;
import com.formiaomiao.demain.service.FriendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value = "/friend")
public class FriendController {

    @Autowired
    FriendService friendService;

    /**
     * 添加好友
     *
     * @param friendfrom
     * @param neteaseUid
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/add")
    private Object InsertFriend(@RequestParam(name = "friendfrom", required = false) Integer friendfrom,
                                @RequestParam(name = "neteaseUid", required = false) String neteaseUid) {
        FriendBean friendBean = new FriendBean();
        friendBean.setFriendfrom(friendfrom);
        friendBean.setNeteaseUid(neteaseUid);
        return friendService.InsertFriend(friendBean);
    }

    /**
     * 删除好友
     *
     * @param friendfrom
     * @param friendto
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/delete")
    private Object DeleteFriend(@RequestParam(name = "friendfrom", required = false) Integer friendfrom,
                                @RequestParam(name = "friendto", required = false) Integer friendto) {
        FriendBean friendBean = new FriendBean();
        friendBean.setFriendfrom(friendfrom);
        friendBean.setFriendto(friendto);
        return friendService.DeleteFriend(friendBean);
    }

    /**
     * 查询好友关系
     *
     * @param friendfrom
     * @param friendto
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/select")
    private Object SelectFriend(@RequestParam(name = "friendfrom", required = false) Integer friendfrom,
                                @RequestParam(name = "friendto", required = false) Integer friendto) {
        FriendBean friendBean = new FriendBean();
        friendBean.setFriendfrom(friendfrom);
        friendBean.setFriendto(friendto);
        return friendService.SelectFriend(friendBean);
    }

}
